class ApiLogger {
  static const bool _isDebugMode = true; // 可以根据环境配置

  static void logRequest(String method, String url, {Map<String, dynamic>? params, dynamic data}) {
    if (!_isDebugMode) return;
    
    print('');
    print('🔥' * 50);
    print('📤 [API REQUEST] $method $url');
    print('🕒 时间: ${DateTime.now().toIso8601String()}');
    
    if (params != null && params.isNotEmpty) {
      print('📝 查询参数:');
      params.forEach((key, value) => print('   $key: $value'));
    }
    
    if (data != null) {
      print('📄 请求体: $data');
    }
    print('🔥' * 50);
  }

  static void logResponse(int? statusCode, String? statusMessage, dynamic data) {
    if (!_isDebugMode) return;
    
    print('');
    print('✅' * 50);
    print('📥 [API RESPONSE] $statusCode $statusMessage');
    print('🕒 时间: ${DateTime.now().toIso8601String()}');
    print('📦 响应数据: $data');
    print('✅' * 50);
    print('');
  }

  static void logError(String errorType, String message, {dynamic response}) {
    if (!_isDebugMode) return;
    
    print('');
    print('❌' * 50);
    print('💥 [API ERROR] $errorType');
    print('🕒 时间: ${DateTime.now().toIso8601String()}');
    print('📝 错误信息: $message');
    
    if (response != null) {
      print('📦 错误响应: $response');
    }
    print('❌' * 50);
    print('');
  }

  static void logService(String serviceName, String action, {String? result, String? error}) {
    if (!_isDebugMode) return;
    
    final icon = error != null ? '❌' : '✅';
    final status = error != null ? 'ERROR' : 'SUCCESS';
    
    print('');
    print('$icon [$serviceName] $action - $status');
    print('🕒 时间: ${DateTime.now().toIso8601String()}');
    
    if (result != null) {
      print('📝 结果: $result');
    }
    
    if (error != null) {
      print('❌ 错误: $error');
    }
  }

  static void logProvider(String providerName, String action, {String? data}) {
    if (!_isDebugMode) return;
    
    print('🎯 [$providerName] $action');
    if (data != null) {
      print('📝 数据: $data');
    }
  }

  // 添加一些预定义的便捷方法
  static void logLoveQuoteRequest() {
    logService('LOVE_QUOTE_SERVICE', '开始获取每日情话');
  }

  static void logLoveQuoteSuccess(String content) {
    logService('LOVE_QUOTE_SERVICE', '获取每日情话成功', result: '"$content"');
  }

  static void logLoveQuoteError(String error) {
    logService('LOVE_QUOTE_SERVICE', '获取每日情话失败', error: error);
  }

  static void logFallbackQuote(String content) {
    print('');
    print('🏠' * 30);
    print('💝 [FALLBACK] 使用默认情话: "$content"');
    print('🕒 时间: ${DateTime.now().toIso8601String()}');
    print('🏠' * 30);
    print('');
  }
}